import 'package:flutter/material.dart';
import 'package:word_range_client/pages/general/Mall.dart';

import '../../pojo/Result.dart';
import '../../viewModels/UserViewModel.dart';

class ActivityIntegral extends StatefulWidget {
  const ActivityIntegral({super.key});

  @override
  State<ActivityIntegral> createState() => _ActivityIntegralState();
}

class _ActivityIntegralState extends State<ActivityIntegral> {

  String userActivityIntegral = "----";

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _loadUserActivityIntegral();
  }

  void _loadUserActivityIntegral() async {
    Result result = await UserViewModel().getUserActivityIntegral();
    if(result.code == 1){
      setState(() {
        userActivityIntegral = result.data.toString();
      });
    }
  }

  void _toMallPage(){
    Navigator.push(
      context,
      MaterialPageRoute(
          builder: (context) => const Mall()
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialButton(
        padding: const EdgeInsets.all(0),
        onPressed: _toMallPage,
        child: Card(
            elevation: 6,
            shape: RoundedRectangleBorder(              // 形状
                borderRadius: BorderRadius.circular(15)   // 圆角
            ),
            margin: const EdgeInsets.all(10),
            child: SizedBox(
              height: 70,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text(
                    "我的积分: $userActivityIntegral",
                    style: const TextStyle(
                        fontSize: 20
                    ),
                  ),
                  const SizedBox(),
                  const Text(
                    "进入积分商城 >",
                    style: TextStyle(
                        fontSize: 15
                    ),
                  )
                ],
              ),
            )
        )
    );
  }
}
